package com.wangp.mywrite.s_netty.netty.ch2;

import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.NettyRuntime;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @description: TODO
 * @author tooStronger
 * @date 2023/3/17
 */
@Slf4j
public class TestEventLoop {

    public static void main(String[] args) {
        // 1. 创建事件循环组
        EventLoopGroup group = new NioEventLoopGroup(2); // io 事件，普通任务，定时任务
//        EventLoopGroup group = new DefaultEventLoopGroup(); // 普通任务，定时任务

        // 2. 获取下一个循环对象
        System.out.println(group.next());
        System.out.println(group.next());
        System.out.println(group.next());

        // 3. 执行普通任务
//        group.next().submit(()->{
//            try {
//                Thread.sleep(1000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//            log.info("ok");
//        });


        // 4. 执行定时任务
        group.next().scheduleAtFixedRate(()-> log.info("ok"),1,1, TimeUnit.SECONDS);
        System.out.println(Thread.currentThread().getName());
    }
}
